//
//  QSBaseMacro.h
//  macroTest
//
//  Created by apple on 2017/5/26.
//  Copyright © 2017年 apple. All rights reserved.
//

#ifndef QSBaseMacro_h
#define QSBaseMacro_h

/**
 *  颜色
 */
/** 16进制颜色 */
#define kUIColorWithHex(s) ([UIColor colorWithRed:(((s & 0xFF0000) >> 16))/255.0 green:(((s &0xFF00) >>8))/255.0 blue:((s &0xFF))/255.0 alpha:1.0])
/** r, g, b颜色 */
#define kUIColorWithARGB(r, g, b, a) ([UIColor colorWithRed:(r / 255.0) green:(g / 255.0) blue:(b / 255.0) alpha:a])
/** 随机颜色 */
#define kUIColorWithRandom [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

/** 常用颜色 */
#define kBlack_color     [UIColor blackColor]
#define kBlue_color      [UIColor blueColor]
#define kBrown_color     [UIColor brownColor]
#define kClear_color     [UIColor clearColor]
#define kDarkGray_color  [UIColor darkGrayColor]
#define kDarkText_color  [UIColor darkTextColor]
#define kWhite_color     [UIColor whiteColor]
#define kYellow_color    [UIColor yellowColor]
#define kRed_color       [UIColor redColor]
#define kOrange_color    [UIColor orangeColor]
#define kPurple_color    [UIColor purpleColor]
#define kLightText_color [UIColor lightTextColor]
#define kLightGray_color [UIColor lightGrayColor]
#define kGreen_color     [UIColor greenColor]
#define kGray_color      [UIColor grayColor]
#define kMagenta_color   [UIColor magentaColor]

/**
 *  字体
 */
/** 系统字体 */
/** 系统字体 */
#define kSystemFontSize(FONTSIZE) [UIFont systemFontOfSize:kAdaptedWidth(FONTSIZE)]
/** 粗体 */
#define kSystemBoldSize(FONTSIZE) [UIFont boldSystemFontOfSize:kAdaptedWidth(FONTSIZE)]
/** 其他字体 */
#define kOtherFontSize(NAME, FONTSIZE) [UIFont fontWithName:(NAME) size:kAdaptedWidth(FONTSIZE)]

/**
 *  屏幕frame，需要判断横屏或者竖屏
 */
#define kScreenBounds ([UIScreen mainScreen].bounds)
/** 需要横屏或者竖屏，获取屏幕宽度与高度 */
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 // 当前Xcode支持iOS8及以上

#define kScreenWidth ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width / [UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)
#define kScreenHeight ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height / [UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)
#define kScreenSize ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width / [UIScreen mainScreen].nativeScale, [UIScreen mainScreen].nativeBounds.size.height / [UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)
#else
#define kScreenWidth ([UIScreen mainScreen].bounds.size.width)
#define kScreenHeight ([UIScreen mainScreen].bounds.size.height)
#define kScreenSize ([UIScreen mainScreen].bounds.size)
#endif

/** 获取当前app显示的frame和宽高 applicationFrame就是app显示的区域，不包含状态栏 */
#define kAPPScreenHeight [[UIScreen mainScreen] applicationFrame].size.height
#define kAPPScreenWidth [[UIScreen mainScreen] applicationFrame].size.width
#define kAPPScreenFrame [[UIScreen mainScreen] applicationFrame]

/**
 *  获取rect的最大X、Y
 */
#define kGetReactMaxX(rect) CGRectGetMaxX(rect)
#define kGetReactMaxY(rect) CGRectGetMaxY(rect)

/** 系统控件默认高度 */
#define kStatusBarHeight (20.f)
#define kTopBarHeight (44.f)
#define kNavBarHeight (64.f)
#define kTabBarHeight (49.f)

/** 系统单例相关 */
/** 文件管理 */
#define kFileManager [NSFileManager defaultManager]
/** userDefault */
#define kUserDefaults   [NSUserDefaults standardUserDefaults]
/** app */
#define kApplication [UIApplication sharedApplication]

/** 弱引用 */
#define kWeakRefrence(type)  __weak typeof(type) weak##type = type
#define kWeakSelf  __weak typeof(self) weakSelf = self
/**
 *  强引用
 */
#define kStrongRerence(type)  __strong typeof(type) type = weak##type

/**
 *  获取window
 */
#define kWindow [UIApplication sharedApplication].keyWindow

/**
 *  圆角和边框
 */
/** 设置view带圆角和边框 */
#define kViewWithBorderAndRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

/** 设置View带圆角 */
#define kViewWithRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

/** 设置View带边框 */
#define kViewWithBorder(View, Width, Color)\
\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

/**
 *  获取图片资源
 */
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
#define kGetImageFromFile(path) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:path ofType:nil]]

/**
 *  转换为字符串
 */
#define kChangeToString(type, value) [NSString stringWithFormat:[NSString stringWithFormat:@"%@", type],value]

/**
 *  空判断
 */
/** 字符串是否为空 */
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
/** 数组是否为空 */
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
/** 字典是否为空 */
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
/** 是否是空对象 */
#define kObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

/**
 *  GCD 的宏定义，注意block要写在^{}里面
 */
/** GCD - 一次性执行 */
#define kDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);
/** GCD - 在Main线程上运行 */
#define kDISPATCH_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);
/** GCD - 开启异步线程 */
#define kDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);

/**
 *  判断当前的iPhone设备
 */
/** iPhone */
#define kIS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
/** iPad */
#define kIS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
/** ipod */
#define kIS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])

/** 系统版本 */
#define kIOS_VERSION ([[[UIDevice currentDevice] systemVersion] floatValue])

/**
 *  目录路径
 */
/** home目录 */
#define kHomeDirectory (NSHomeDirectory())
/** document目录 */
#define kDocumentDirectory (NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject)
/** Cache目录 */
#define kCacheDirectory (NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject)
/** Library目录 */
#define kLibraryDirectory (NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).firstObject)
/** Tmp目录 */
#define kTmpDirectory (NSTemporaryDirectory())

#endif /* QSBaseMacro_h */
